<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require 'dbcon.php';
$page=isset($_GET['page'])?$_GET['page']:1;//说明现在页码
$pagesize=18;//定义每页多少条留言
$first=($page-1)*$pagesize;//算初始位置 
$sql="select b.*, a.nickname,c.name from users a,posts b,categories c where b.user_id=a.id and b.category_id=c.id order by id desc limit {$first},{$pagesize}";
$result=$db->query($sql);
$num=$result->num_rows;//不分页的总的记录数
//这个总的记录数可以给我们计算  总页数=ceil(总的记录数/pagesize)
$maxpage=ceil($num/$pagesize);
$posts=$result->fetch_all(MYSQLI_ASSOC);//产生的这个数组是二维关联数组，下标是字符串
$result->free_result();
$db->close();//关闭数据库连接
require "posts.php";
